﻿package com.ufenlei.LTS{
	import flash.events.ProgressEvent;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ScrolledBlock extends Block{
		private var _scroll:Scroll;
		public function ScrolledBlock(w:uint = 400,h:uint=300){
			super(w,h);
			_scroll = new Scroll(this.bHeight);
			_scroll.x = this.bWidth - 20;
			_scroll.addEventListener(Scroll.UPDATE, onScrollUpdate);
			addChild(_scroll);
			updateScroll();			
			this.addEventListener(Event.CHANGE,onChange );
			this.addEventListener(MouseEvent.MOUSE_WHEEL,onWheel);
		}
		public function updateScroll():void{
			if(trueHeight > bHeight){
				var d:int = trueHeight - bHeight;				
				_scroll.barHeight = bHeight;
				_scroll.scrollHeight = d;
			}else{
				_scroll.barHeight = bHeight;
				_scroll.scrollHeight = 0;
			}
		}
		private function onWheel(evt:MouseEvent):void{
			_scroll.moveBy(evt.delta * -6);
		}
		private function onScrollUpdate(evt:ProgressEvent):void{
			//trace(trueHeight,bHeight);
			//trace(evt);
			if(trueHeight > bHeight){
				this._container.y = -1 * (trueHeight - bHeight ) * evt.bytesLoaded / evt.bytesTotal;
			}
		}
		private function onChange(evt:Event):void{
			updateScroll();
		}
	}
}